/**
 * Created by Emily on 16/1/27.
 */
var WebSocketServer = require('ws').Server;
var wss = new WebSocketServer({port: 5454});

console.log("Persistence running on port 5454");

var handler = {};

wss.on('connection', function connection(socket){
    console.log(socket.host + " has been connected in !");
    socket.on('message', function incoming(message){
        console.log(message);
        console.log(JSON.parse(message));
        if (handler[message.action] != null) {
           handler[message.action](socket.message);
        }
    });

});

handler["authentication"] = function(socket, message) {
    console.log("authentication -> " + socket.host + " - " + message);
}
